<?php

$form = $this->beginWidget(
            'bootstrap.widgets.TbActiveForm',
            array(
                'id' => 'tr-mdokter-profile-form',
                'enableAjaxValidation' => false,
            )
        );

echo '<p class="help-block">Fields  <span class="required">*</span> Wajib diisi.</p>';

echo $form->errorSummary($model);

$options = array(
    'success' => "js:function(data, textStatus, XMLHttpRequest) {
        location.reload();
    }",
    'error' => 'js:function(XMLHttpRequest, textStatus, errorThrown) { alert("Error Data"); }'
);

echo $form->hiddenField($model,'dokter_id_hd',array('value' => $_GET['id']));
//echo $form->hiddenField($model,'id',array('value' => '202'));

echo $form->dropDownList($model,'profile_id', CHtml::listData(TrMProfile::model()->findAll(array('condition'=>"t.table = 'tr_m_medic_profile'",'order'=>'t.sort ASC','limit'=>'20')), 'id', 'name'), 
        array('options' => array(
            'empty'=>'Select',),
            'ajax'=> array(
                'type'=>'POST',
                'url'=>CController::createUrl('trMMedicProfile/profiletype'),
                'data'=>array('profile_id'=>'js:this.value',),
                'success'=>'function(data){
                                //alert(profileJSON.type);
								var profileJSON = jQuery.parseJSON(data);
								$("#profile_value").html("");
								if (profileJSON.type == "radio")
								{
								$("#TrMMrProfile_penjamin").hide();
									var profileValue = profileJSON.value;
									for (var i=0;i<profileValue.length;i++)
									{
										$("#profile_value").append("<input id=\'TrMMrProfile_value_" + i +"\' type=\'radio\' name=\'TrMDokterProfile[isi]\' value=\'" + profileValue[i] + "\'></input> " + profileValue[i] + " <br>");
									}
								} else if(profileJSON.type=="penjamin") {
								$("#TrMMrProfile_penjamin").show();

								} else
								{
									$("#profile_value").html("<textarea id=\'TrMMrProfile_value\'  class=\'span8\' name=\'TrMDokterProfile[isi]\' cols=\'50\' rows=\'6\'></textarea>");
								}
							}',
            ),




        )



        );
echo "<div id='profile_value'></div>";
echo "&nbsp";
//echo $form->textField($model,'isi', array('class' => 'span5'));
echo '<div class="form-actions">';
echo CHtml::ajaxSubmitButton($model->isNewRecord ? 'Update' : 'Simpan',  CHtml::normalizeUrl(array('TrMDokterProfile/addProfile')),$options,array('class' => 'btn btn-primary'));

/*
$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'submit',
    'type' => 'primary',
    'label' => $model->isNewRecord ? 'Lanjut' : 'Simpan',
));
*/
echo '</div>';

$this->endWidget();
